package spring.example.cloud.service.impl;

import cloud.estate.commons.bean.Parking;
import cloud.estate.commons.handler.exception.*;
import cloud.estate.commons.mapper.ParkingMapper;
import cloud.estate.commons.util.JsonResult;
import cloud.estate.commons.util.ResultTool;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import spring.example.cloud.service.parkingService;

@Service
public class parkingServiceImpl extends ServiceImpl<ParkingMapper, Parking> implements parkingService {
    @Override
    public JsonResult addOneParking(Parking parking){
        try {
            boolean save = save(parking);
            if (save){
                return  ResultTool.success("添加成功");
            }
            return ResultTool.fail(501,"添加失败");
        } catch (Exception e) {
            throw new AddOneException(e.getMessage());
        }
    }
    @Override
    public JsonResult deleteOneParking(String id){
        try {
            boolean removeById = removeById(id);
            if (removeById){
                return  ResultTool.success("删除成功");
            }
            return ResultTool.fail(502,"删除失败");
        } catch (Exception e) {
            throw new DealOneByIdException(e.getMessage());
        }
    }
    @Override
    public JsonResult updateOneParking(Parking parking){
        try {
            boolean updateById = updateById(parking);
            if (updateById){
                return  ResultTool.success("更新成功");
            }
            return ResultTool.fail(503,"更新失败");
        } catch (Exception e){
            throw new UpdateOneException(e.getMessage());
        }
    }
    @Override
    public JsonResult getOneParking(String id){
        try {
            Parking parking = getById(id);
            if (parking != null){
                return  ResultTool.success(parking);
            }
            return ResultTool.fail(504,"查询失败");
        } catch (Exception e) {
            throw new FindOneException(e.getMessage());
        }
    }
    @Override
    public JsonResult listAllParking(){
        try {
            return  ResultTool.success(list());
        } catch (Exception e) {
            throw new FindAllException(e.getMessage());
        }
    }
}
